from django.contrib import admin
from .models import College, Major, Classes, Course, Punish, Score

# Register your models here.

@admin.register(College)
class CollegeAdmin(admin.ModelAdmin):
    list_display = ['id', 'college_name']
    search_fields = ['college_name']
    list_per_page = 20


@admin.register(Major)
class MajorAdmin(admin.ModelAdmin):
    list_display = ['id', 'major_name', 'college']
    list_filter = ['college']
    search_fields = ['major_name']
    list_per_page = 20


@admin.register(Classes)
class ClassesAdmin(admin.ModelAdmin):
    list_display = ['id', 'class_name', 'teacher', 'major']
    list_filter = ['major', 'teacher']
    search_fields = ['class_name']
    list_per_page = 20


@admin.register(Course)
class CourseAdmin(admin.ModelAdmin):
    list_display = ['id', 'course_name']
    search_fields = ['course_name']
    list_per_page = 20


@admin.register(Punish)
class PunishAdmin(admin.ModelAdmin):
    list_display = ['id', 'student', 'name', 'sort', 'ranks', 'grade', 'teacher', 'time', 'created_at']
    list_filter = ['sort', 'ranks', 'time', 'teacher']
    search_fields = ['student__username', 'name', 'teacher__username']
    list_per_page = 20
    ordering = ['-created_at']
    readonly_fields = ['created_at']


@admin.register(Score)
class ScoreAdmin(admin.ModelAdmin):
    list_display = ['id', 'student', 'time', 'grade', 'zb_grade', 'db_grade', 'tb_grade', 'fail']
    list_filter = ['time', 'fail']
    search_fields = ['student__username']
    list_per_page = 20
    ordering = ['-time', 'student']
    readonly_fields = ['created_at', 'updated_at']
    
    fieldsets = [
        ('基本信息', {
            'fields': ['student', 'time', 'grade', 'fail']
        }),
        ('基本分', {
            'fields': ['zb_grade', 'db_grade', 'tb_grade']
        }),
        ('附加分', {
            'fields': ['za_grade', 'da_grade', 'ta_grade']
        }),
        ('元数据', {
            'fields': ['created_at', 'updated_at'],
            'classes': ['collapse']
        }),
    ]
